package main;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class TracerProperties extends Properties {	
	
	private static final long serialVersionUID = -8603422844271401733L;

	public TracerProperties() {
		Properties defaults = new Properties();
		
		// image properties
		defaults.setProperty("output_width", "640");
		defaults.setProperty("output_height", "480");
		
		// shading
		defaults.setProperty("shading_ambient", Boolean.toString(true));
		defaults.setProperty("shading_diffuse", Boolean.toString(true));
		defaults.setProperty("shading_specular", Boolean.toString(true));
		
		// tracing
		defaults.setProperty("trace_reflections", Boolean.toString(false));
		defaults.setProperty("trace_shadows", Boolean.toString(false));
		defaults.setProperty("trace_transmissions", Boolean.toString(false));
		defaults.setProperty("trace_level", Integer.toString(10));
		
		// global illumination
		defaults.setProperty("diffuse", Boolean.toString(false));
		defaults.setProperty("diffuse_density", Integer.toString(100));
		
		// depth of field
		defaults.setProperty("dof", Boolean.toString(false));
		defaults.setProperty("dof_distribution", Integer.toString(0));
		defaults.setProperty("dof_lensSize", Double.toString(0.2));
		defaults.setProperty("dof_scatter", Double.toString(0.01));
		defaults.setProperty("dof_focalDistance", Double.toString(4.0));
		
		// motion blur
		defaults.setProperty("motionBlur", Boolean.toString(false));
		defaults.setProperty("motionBlur_increment", Double.toString(0.1));
		defaults.setProperty("motionBlur_steps", Integer.toString(10));
		
		// soft shadows
		defaults.setProperty("softShadows", Boolean.toString(true));
		defaults.setProperty("softShadows_density", Integer.toString(10));
		
		// sampling
		defaults.setProperty("sampling_whitted", Boolean.toString(false));
		defaults.setProperty("sampling_fraction", Double.toString(1));

		
		this.defaults = defaults;
	}
	
	public TracerProperties(String fname) {
		this();
		load(fname);
	}
	
	public void store(String fname) {
		try {
			FileOutputStream fos = new FileOutputStream(fname);
			store(fos, "Tracer Properties");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void storeDefaults() {
		try {
			FileOutputStream fos = new FileOutputStream("defaults.txt");
			defaults.store(fos, "Raytracer Default Properties");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void load(String fname) {		
		try {
			FileInputStream fis = new FileInputStream(fname);
			load(fis);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	 

}
